<template>
  <div id="app">
    <el-container>
      <el-header>
        <MyHeader></MyHeader>
      </el-header>
      <el-main>
        <transition name="el-fade-in">
          <router-view></router-view>
        </transition>
      </el-main>
    </el-container>
  </div>
</template>

<script>
import MyHeader from "./components/MyHeader";

export default {
  name: 'app',
  components: {
    MyHeader

  },
  data() {
    return {
      timer: {}
    }
  },
  mounted() {
    this.$store.commit('isLogin')
    this.timer = setTimeout(this.refrashToken, 1000 * 60 * 8)
  },
  beforeDestroy() {
    clearTimeout(this.timer)
  },
  methods: {
    refrashToken() {
      if (this.$store.state.userToken != '') {
        console.log('刷新token')
        let url = 'http://shilezhi.club:8082/Api/User/RefreshToken'
        let postData = {
          pldToken: this.$store.state.userToken
        }
        this.$axios.post(url, JSON.stringify(postData)).then(
            response => {
              if (response.data.code === 'ok') {
                this.$store.commit('setUserToken', response.data.newToken)
              } else {
                this.$message.warning('token刷新失败重新登录')
              }
            },
            error => {
              console.log(error)
            }
        )
      }


    }
  }
}
</script>

<style>
* {
  margin: 0;
  padding: 0;
}

#app {

}

a {
  text-decoration: none;
  color: inherit;

}

.el-header {
  padding: 0 !important;

}

.el-main {
  padding: 0 !important;
}
</style>
